package top.archiesean.admin.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.archiesean.admin.dto.UserInfo;
import top.archiesean.admin.pojo.SysUser;
import top.archiesean.common.core.domain.R;
import top.archiesean.common.log.annotation.SysLog;
import top.archiesean.common.security.annotation.AnonymousAccess;

import java.util.HashSet;
import java.util.List;

/**
 * @author ArchieSean
 * @description 用户api
 * @date 2024-01-23 17:37
 */
@Slf4j
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final BCryptPasswordEncoder bCryptPasswordEncoder;

    /**
     * 登录接口使用
     *
     * @return
     */
    @GetMapping("/{username}")
    @SysLog("用户登录使用")
    @AnonymousAccess
    public R<UserInfo> loadByUsername(@PathVariable(name = "username") String username) {
        log.info("获取到的账号为：{}", username);
        return R.success(new UserInfo(new SysUser(1L, 1L, "admin", bCryptPasswordEncoder.encode("123456"),"1235678"),
                new HashSet<>(List.of("abc")), new HashSet<>(List.of("admin"))));
    }
}
